package com.wkq.jdbctemplate.controler;

import com.wkq.jdbctemplate.commons.Record;
import com.wkq.jdbctemplate.pojo.Goods;
import com.wkq.jdbctemplate.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @PostMapping
    public Integer add(@RequestBody Goods goods) {
        return goodsService.add(goods);
    }

    @GetMapping("/{id}")
    public Record add(@PathVariable Long id) {
        return (Record) goodsService.getById(id);
    }

    @GetMapping
    public List<Goods> list() {
        return goodsService.list();
    }

    @DeleteMapping("{id}")
    public Integer deleteById(@PathVariable Long id) {
        return goodsService.del(id);
    }

    @PutMapping("/{id}")
    public Integer updateById(@PathVariable Long id, @RequestBody Goods goods) {
        goods.setId(id);
        return goodsService.update(goods);
    }

}
